import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"

export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs))
}

// sessionStorage
export const setSession = (key: string, value: any) => {
  if (key && (value || value === 0)) {
    const type = typeof value
    let val = JSON.stringify(value)
    if (type === 'string') {
      val = value
    }
    sessionStorage.setItem(key, val)
  } else {
    throw new Error(`Missing 'key' or 'value'`)
  }
}
export const getUserSession = (key: string) => {
  const val = sessionStorage.getItem(key)
  if (val) {
    try {
      return JSON.parse(val)
    } catch (e) { }
  }
  return val
}

export const RemoveSession = (key: string) => {
  sessionStorage.removeItem(key)
}